import JSEncrypt from 'jsencrypt/bin/jsencrypt'

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey = `-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAny9gpMMo6xfi3kUzOKXd
4EmM1eb3Pgq4vQ8bwgjf1RFmR+8O+UObPqJ18ay2/XOtip5VH52GmqwvXELuW/Bh
rP3TPz2Mrm5hA18itbK9pFwUUi0EkqMRggTiEDddd/TOmnZnv6kxYw7Oq+b4aXVg
uwM5600apoMrKgEF8QXrJfPmKW0QsuxdhE7pK+gs15J264vwqzTgYaqrPawvitKm
ZXWPNL7T5qJ8fa/gy2RLG7sPacHEqb+7iBift7jSeQaoqzjyekV42Pdxd7ryuH58
gMdADMm9v7UpyrGRi/M6XK2PXLJm/QDFLWJbhJ7JqPdQ39Zl+zjvnmQDbDrZ23zR
hQIDAQAB
-----END PUBLIC KEY-----`

const privateKey = `-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCfL2CkwyjrF+Le
RTM4pd3gSYzV5vc+Cri9DxvCCN/VEWZH7w75Q5s+onXxrLb9c62KnlUfnYaarC9c
Qu5b8GGs/dM/PYyubmEDXyK1sr2kXBRSLQSSoxGCBOIQN1139M6adme/qTFjDs6r
5vhpdWC7AznrTRqmgysqAQXxBesl8+YpbRCy7F2ETukr6CzXknbri/CrNOBhqqs9
rC+K0qZldY80vtPmonx9r+DLZEsbuw9pwcSpv7uIGJ+3uNJ5BqirOPJ6RXjY93F3
uvK4fnyAx0AMyb2/tSnKsZGL8zpcrY9csmb9AMUtYluEnsmo91Df1mX7OO+eZANs
OtnbfNGFAgMBAAECggEBAJEcAT9w4HYemiMAdgbnvPDeW1IKb8vQvkMp6KXirRhv
+gsM81tqs7RPKLEcPtugfcxlNTfSw4dv+uRh5yNMZ93orI9zrjC8UhdevCdiPtn7
TlLy0r5RhH4/sUwTDFNziHrqAP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1O
mGo1EmKecHwENw/+lp6ed/U=
-----END PRIVATE KEY-----`

// 加密
export function encrypt (txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(publicKey) // 设置公钥
  return encryptor.encrypt(txt) // 对数据进行加密
}

// 解密
export function decrypt (txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPrivateKey(privateKey) // 设置私钥
  return encryptor.decrypt(txt) // 对数据进行解密
}
